package gspushmq.v1.app.subscribeapp.enumeration;

import org.apache.commons.lang3.StringUtils;

public enum PushTypeEnum {

    GROUP(40001, "特定群组"),
    USERS(40002, "指定用户");

    private int code;
    private String name;

    PushTypeEnum(int code, String name) {
        this.code = code;
        this.name = name;
    }

    public static boolean contain(Integer code){
        if (code == null)
            return false;
        for (PushTypeEnum en : PushTypeEnum.values())
            if (en.getCode() == code)
                return true;
        return false;
    }


    public int getCode() {
        return code;
    }

    public void setCode(int code) {
        this.code = code;
    }

    public String getName() {
        return name;
    }

    public void setName(String name) {
        this.name = name;
    }
    public static Integer getCodeByName(String name){
        if (StringUtils.isBlank(name))
            return null;

        for (PushTypeEnum pe : PushTypeEnum.values())
            if (pe.getName().equals(name))
                return pe.getCode();

        return null;
    }

    public static String getNameByCode(Integer code){
        if (code == null)
            return null;

        for (PushTypeEnum pe : PushTypeEnum.values())
            if (pe.getCode() == code)
                return pe.getName();

        return null;
    }
}
